package test_junit_shop.ProductStock;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

import java.util.UUID;

/**
 * Created by ZH on 2018/1/29.
 * 门店-添加产品
 */
public class AddProduction {

    private static AddProduction ap = new AddProduction();
    private WebDriver driver;
    private String ProductIndex= UUID.randomUUID().toString().substring(6);

    public static AddProduction getInstance(){
        return ap;
    }
    public WebDriver getwDriver(){
        return driver;
    }

    public void setwDriver(WebDriver w){
        driver = w;
    }


    public void switchMenu() throws InterruptedException {
        driver.findElement(By.linkText("产品库存")).click();
        Thread.sleep(200);
        driver.findElement(By.linkText("产品档案")).click();
        Thread.sleep(200);
        driver.findElement(By.linkText("产品详情列表")).click();
    }


    public void addProduction() throws InterruptedException {
        Thread.sleep(200);
        //切换Frame
        driver = driver.switchTo().frame(2);
        driver = driver.switchTo().frame(0);
        Thread.sleep(1000);
        driver.findElements(By.cssSelector("i.jstree-icon.jstree-ocl")).get(1).click();
        driver.findElement(By.id("44172_anchor")).click();
        driver=driver.switchTo().parentFrame();
        driver = driver.switchTo().frame(1);
        Thread.sleep(300);
        driver.findElement(By.cssSelector("button.btn.btn-sm.btn-outline.btn-primary")).click();
        driver = driver.switchTo().frame(0);
        Thread.sleep(1000);
        driver.findElement(By.name("productName")).click();
        driver.findElement(By.name("productName")).clear();
        driver.findElement(By.name("productName")).sendKeys("测试用例");
        driver.findElement(By.name("productNo")).click();
        driver.findElement(By.name("productNo")).clear();
        driver.findElement(By.name("productNo")).sendKeys(ProductIndex);
        driver.findElement(By.id("tag-name")).click();
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("选择")).click();
        driver = driver.switchTo().frame(0);
        driver.findElement(By.id("level")).click();
        new Select(driver.findElement(By.id("level"))).selectByVisibleText("原厂件");
        driver.findElement(By.cssSelector("option[value=\"1\"]")).click();
        driver.findElement(By.id("type")).click();
        new Select(driver.findElement(By.id("type"))).selectByVisibleText("销售品");
        driver.findElement(By.cssSelector("#type > option[value=\"1\"]")).click();
        driver.findElement(By.id("suggestedPrice")).click();
        driver.findElement(By.id("suggestedPrice")).clear();
        driver.findElement(By.id("suggestedPrice")).sendKeys("2000");
        driver.findElement(By.id("purchasePrice")).click();
        driver.findElement(By.id("purchasePrice")).clear();
        driver.findElement(By.id("purchasePrice")).sendKeys("1000");
        driver.findElement(By.name("shortName")).click();
        driver.findElement(By.name("shortName")).clear();
        driver.findElement(By.name("shortName")).sendKeys("测试专用");
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("下一步")).click();
    }

    public void addProductionWarehouse() throws InterruptedException {
        Thread.sleep(1000);
        driver = driver.switchTo().frame(0);
        Thread.sleep(2000);
        driver.findElement(By.id("brandId")).click();
        driver.findElement(By.xpath("//div[@id='brandIdbox']/div/div/ul/li[3]")).click();
        driver.findElement(By.name("manufacturerNo")).click();
        driver.findElement(By.name("manufacturerNo")).clear();
        driver.findElement(By.name("manufacturerNo")).sendKeys("2000");
        driver.findElement(By.name("productType")).click();
        driver.findElement(By.name("productType")).clear();
        driver.findElement(By.name("productType")).sendKeys("3000");
        driver.findElement(By.name("spec")).click();
        driver.findElement(By.name("spec")).clear();
        driver.findElement(By.name("spec")).sendKeys("20");
        driver.findElement(By.name("barcode")).click();
        driver.findElement(By.name("barcode")).clear();
        driver.findElement(By.name("barcode")).sendKeys("30");
        driver.findElement(By.id("stockUnitGroupId")).click();
        new Select(driver.findElement(By.id("stockUnitGroupId"))).selectByVisibleText("单元");
        driver.findElement(By.cssSelector("#stockUnitGroupId > option[value=\"12\"]")).click();
        driver.findElement(By.id("stockUnitId")).click();
        new Select(driver.findElement(By.id("stockUnitId"))).selectByVisibleText("颗");
        driver.findElement(By.cssSelector("#stockUnitId > option[value=\"77\"]")).click();
        driver.findElement(By.name("attrDto.manufacturerPrice")).click();
        driver.findElement(By.name("attrDto.manufacturerPrice")).clear();
        driver.findElement(By.name("attrDto.manufacturerPrice")).sendKeys("2000");
        driver.findElement(By.name("attrDto.combinationMinAmount")).click();
        driver.findElement(By.name("attrDto.combinationMinAmount")).clear();
        driver.findElement(By.name("attrDto.combinationMinAmount")).sendKeys("20");
        driver.findElement(By.name("attrDto.durabilityPeriod")).click();
        driver.findElement(By.name("attrDto.durabilityPeriod")).clear();
        driver.findElement(By.name("attrDto.durabilityPeriod")).sendKeys("3");
        driver.findElement(By.name("attrDto.durabilityPreWarm")).click();
        driver.findElement(By.name("attrDto.durabilityPreWarm")).clear();
        driver.findElement(By.name("attrDto.durabilityPreWarm")).sendKeys("20");
        driver.findElement(By.name("attrDto.minStockAmount")).click();
        driver.findElement(By.name("attrDto.minStockAmount")).clear();
        driver.findElement(By.name("attrDto.minStockAmount")).sendKeys("2");
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("下一步")).click();
    }

    public void addProductionPrice() throws InterruptedException {
        Thread.sleep(1000);
        driver = driver.switchTo().frame(0);
        driver.findElement(By.name("shopPrice")).click();
        driver.findElement(By.name("shopPrice")).clear();
        driver.findElement(By.name("shopPrice")).sendKeys("200");
        driver.findElement(By.name("combinationPrice")).click();
        driver.findElement(By.name("combinationPrice")).clear();
        driver.findElement(By.name("combinationPrice")).sendKeys("100");
        driver.findElement(By.id("defaultWarehouse")).click();
        new Select(driver.findElement(By.id("defaultWarehouse"))).selectByVisibleText("门店创建仓库");
        driver.findElement(By.cssSelector("option[value=\"36\"]")).click();
        driver.findElement(By.name("onlinePrice")).click();
        driver.findElement(By.name("onlinePrice")).clear();
        driver.findElement(By.name("onlinePrice")).sendKeys("200");
        driver.findElement(By.name("minRetailPrice")).click();
        driver.findElement(By.name("minRetailPrice")).clear();
        driver.findElement(By.name("minRetailPrice")).sendKeys("100");
        driver.findElement(By.name("chainPrice")).click();
        driver.findElement(By.name("chainPrice")).clear();
        driver.findElement(By.name("chainPrice")).sendKeys("300");
        driver.findElement(By.name("leaguePrice")).click();
        driver.findElement(By.name("leaguePrice")).clear();
        driver.findElement(By.name("leaguePrice")).sendKeys("400");
        driver.findElement(By.id("allowedAllocation")).click();
        new Select(driver.findElement(By.id("allowedAllocation"))).selectByVisibleText("是");
        driver.findElement(By.cssSelector("option[value=\"1\"]")).click();
        driver.findElement(By.name("maxStockAmountList")).click();
        driver.findElement(By.name("maxStockAmountList")).clear();
        driver.findElement(By.name("maxStockAmountList")).sendKeys("300");
        driver.findElement(By.id("warning")).click();
        new Select(driver.findElement(By.id("allowedAllocation"))).selectByVisibleText("是");
        driver.findElement(By.cssSelector("option[value=\"1\"]")).click();
        driver.findElement(By.name("maxStockAmountList")).click();
        driver.findElement(By.name("maxStockAmountList")).clear();
        driver.findElement(By.name("maxStockAmountList")).sendKeys("20000");
        driver.findElement(By.id("warning")).click();
        new Select(driver.findElement(By.id("warning"))).selectByVisibleText("是");
        driver.findElement(By.cssSelector("#warning > option[value=\"1\"]")).click();
        driver.findElement(By.id("warnAmount_36")).click();
        driver.findElement(By.id("warnAmount_36")).clear();
        driver.findElement(By.id("warnAmount_36")).sendKeys("20");
        driver=driver.switchTo().parentFrame();
        driver.findElement(By.linkText("下一步")).click();
    }

    public void addProductionFactory() throws InterruptedException {
        Thread.sleep(1000);
        driver.findElement(By.linkText("确定")).click();
    }

}
